import 'package:FineArt/constants.dart';
import 'package:FineArt/core/api/home_api.dart';
import 'package:FineArt/core/utils/toast.dart';
import 'package:FineArt/core/widget/grid/grid_item.dart';
import 'package:FineArt/core/widget/list/article_item.dart';
import 'package:FineArt/core/widget/web_view_page.dart';
import 'package:FineArt/page/tab/component/recommend_group_item.dart';
import 'package:FineArt/page/tab/recommend/component/recommendItem.dart';
import 'package:FineArt/utils/log_util.dart';
import 'package:FineArt/utils/size_config.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class RecommendItemMore extends StatefulWidget {
  final String typeName;
  final String type;

  RecommendItemMore(this.typeName, this.type);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _RecommendMoreState();
  }
}

class _RecommendMoreState extends State<RecommendItemMore> {
  final List groupList = new List();
  var types = ["works", "techart", "tutor"];

  void _getWorks(pg, size) {
    HomeApi().works(pg, size).then((res) {
      if (res.code == 200) {
        setState(() {
          groupList.clear();
          groupList.addAll(res.data.list);
        });
      }
    });
  }

  void _getTecharts(pg, size) {
    HomeApi().techarts(pg, size).then((res) {
      if (res.code == 200) {
        setState(() {
          groupList.clear();
          groupList.addAll(res.data.list);
        });
      }
    });
  }

  void _getTutors(pg, size) {
    HomeApi().teachers(pg, size).then((res) {
      if (res.code == 200) {
        setState(() {
          groupList.clear();
          groupList.addAll(res.data.list);
        });
      }
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (widget.type == "works") {
      _getWorks(0, PAGE_SIZE);
    } else if (widget.type == "techart") {
      _getTecharts(0, PAGE_SIZE);
    } else if (widget.type == "tutor") {
      _getTutors(0, PAGE_SIZE);
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
          title: Text(
            widget.typeName,
            style: TextStyle(color: text_black),
          ),
          centerTitle: true,
          leading: SizedBox(
              width: getPortraitSWidth(17),
              height: getPortraitSHeight(17),
              child: InkWell(
                child: IconButton(
                  icon: Icon(Icons.arrow_back_ios, color: text_black),
                ),
                onTap: () {
                  Navigator.of(context).pop();
                },
              )),
          backgroundColor: Colors.white,
          brightness: Brightness.dark,
          actions: [
            InkWell(
              child: Icon(
                Icons.add,
                color: text_black,
              ),
              onTap: () {},
            ),
            SizedBox(
              width: getPortraitSWidth(10),
            )
          ],
          elevation: 0,
          iconTheme:
              IconThemeData(color: Colors.black, opacity: 0.5, size: 30)),
      body:
          // Text(widget.typeName),
          Center(
        child: EasyRefresh.custom(
          header: MaterialHeader(),
          footer: MaterialFooter(),
          onRefresh: () async {},
          onLoad: () async {},
          slivers: <Widget>[
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) {
                  return RecommendGroupItem(group: groupList[index]);
                },
                childCount: groupList.length,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
